//
//  GuangGaoViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/11/1.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "GuangGaoViewController.h"
#import "GuangGaoTableViewCell.h"
#import "GuangXiangViewController.h"
@interface GuangGaoViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation GuangGaoViewController
{
    RWScrollView * _table;
    int _page;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 1;
    [self drawNavWithTitle:@"广告列表" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    [self drawBackButton];
    _table = [[RWScrollView alloc]initWithFrame:CGRectMake(0, 64, KScreenWidth, KScreenHeight-64)];
    _table.delegate = self;
    _table.dataSource = self;
    
    [_table addHeaderWithTarget:self action:@selector(headRefresh)];
    [_table addFooterWithTarget:self action:@selector(footerRefresh)];
    [_table headerBeginRefreshing];
    [_table registerClass:[GuangGaoTableViewCell class] forCellReuseIdentifier:@"cell"];
    _table.separatorStyle = UITableViewCellSelectionStyleNone;
   
    [self.view addSubview:_table];
}


-(void)headRefresh{
    _page = 1;
    [self requestDataWith:1];
}
-(void)footerRefresh{
    _page ++;
    [self requestDataWith:0];
}
-(void)requestDataWith:(int)first{
    NSMutableDictionary * requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setObject:@"10" forKey:@"pageSize"];
    [requestDic setObject:[NSString stringWithFormat:@"%d",_page] forKey:@"pageNum"];
    [NetWorking NEWjieKouQingQiu:@"" ANDIP:IP And:requestDic anBlock:^(NSDictionary *dic, NSError *error) {
        [_table headerEndRefreshing];
        [_table footerEndRefreshing];
        if (!error) {
            if ([requestDic[Code] intValue] == 200) {
                
            }
        }
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 15;
}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GuangGaoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.95 alpha:1.00];
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
     [cell.image sd_setImageWithURL:[NSURL URLWithString:[self requestImageStr]]];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    GuangXiangViewController * xiang = [[GuangXiangViewController alloc]init];
    [self.navigationController pushViewController:xiang animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
